<?php

use yii\helpers\Url;
use yii\widgets\Pjax;
use yii\widgets\LinkPager;

$this->inline("title","文章列表");
?>
<div class="panel">
    <div class="panel-body">
        <div class="card-box">
            <div class="row">
                <div class="col-sm-6">
                    <div class="m-b-30">
                        <a href="<?=Url::toRoute('/article/add')?>" class="btn btn-primary waves-effect waves-light">
                            添加文章
                            <i class="fa fa-plus"></i>
                        </a>
                    </div>
                </div>
            </div>
            <?php Pjax::begin(['id' => 'item-data-list']);?>
            <div class="">
                <div class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                    <div class="row">
                        <form class="form-horizontal" action="" method="get">
                            <div class="col-sm-3">
                                <div class="dataTables_length">
                                    <label>
                                        <select class="form-control input-sm" name="pageSize">
                                            <option value="10" <?=Yii::$app->request->get('pageSize') == 10 ? 'selected' : ''?>>每页10行</option>
                                            <option value="25" <?=Yii::$app->request->get('pageSize') == 25 ? 'selected' : ''?>>每页25行</option>
                                            <option value="50" <?=Yii::$app->request->get('pageSize') == 50 ? 'selected' : ''?>>每页50行</option>
                                        </select>
                                    </label>
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <div class="dataTables_filter">
                                    <label>
                                        搜索:
                                        <input type="text" name="title" value="<?=Yii::$app->request->get('title')?>" class="form-control input-sm" placeholder="输入文章标题搜索...">
                                    </label>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <table class="table table-striped dataTable no-footer">
                                <thead>
                                <tr role="row">
                                    <th class="col-sm-2 sorting">标题</th>
                                    <th class="col-sm-2 sorting">描述</th>
                                    <th class="col-sm-2 sorting">分类</th>
                                    <th class="col-sm-2 sorting">作者</th>
                                    <th class="col-sm-2 sorting">创建时间</th>
                                    <th class="col-sm-2 sorting">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach($data['items'] as $item):?>
                                    <tr class="gradeA odd">
                                        <td><?=mb_substr($item['title'],0,10,'utf-8').'...'?></td>
                                        <td><?=mb_substr($item['desc'],0,10,'utf-8').'...'?></td>
                                        <td><?=$item['cname']?></td>
                                        <td><?=$item['admin']?></td>
                                        <td><?=date('Y-d-m H:i:s',$item['last_change'])?></td>
                                        <td class="actions">
                                            <a onclick="location.href=this.href" href="<?=Url::toRoute('/article/edit?id='.$item['id'])?>" class="on-default edit-row">
                                                <i class="fa fa-pencil"></i>
                                            </a>
                                            <a data-id="<?php echo $item['id']?>" onclick="app.deleteData(this);return false;" href="<?=Url::toRoute('/article/delete')?>" class="on-default remove-row">
                                                <i class="fa fa-trash-o"></i>
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach;?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="dataTables_info">
                                当前显示 <?=$data['pages']->offset+1?> - <?=$data['pages']->offset+count($data['items'])?> 共 <?=$data['pages']->totalCount?> 记录
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_simple_numbers text-right">
                                <?=LinkPager::widget([
                                    'pagination' => $data['pages'],
                                    'prevPageLabel' => '上一页',
                                    'nextPageLabel' => '下一页',
                                    'firstPageLabel' => '首页',
                                    'lastPageLabel' => '末页',
                                ]);?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php Pjax::end();?>
        </div>
    </div>
</div>
